<!DOCTYPE html>
<html>
<head>

<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-responsive.min.css">

<style type="text/css">
.nav { }
.nav li { float: left; width: 110px; }
.container { background-color: #ffffff; padding: 30px; }
.content { padding: 30px; }
body, h1, h2, h3, h4 { font-family: "Trebuchet MS","Helvetica Neue",Arial,Helvetica,sans-serif,"Georgia";}
body { background-color: #eeeeee; }
header { width: 100%; }
blockquote p { font-size: 14px; }
</style>
<title>ZPar | Joint Chinese Word Segmentation and POS Tagging</title>
</head>

<body>
<div class="table-bordered container">
<div class="content">

<header>
<div class="page-header text-center">
<h1>Joint Chinese Word Segmentation and POS Tagging</h1>
</div>
</header>

<h2><a id="How-to-compile">How to compile</a></h2>
<p>
Suppose that ZPar has been downloaded to the directory <code>zpar</code>. To make the joint Chinese word segmentor and POS tagger, type <code>make chinese.postagger</code>. This will create a directory <code>zpar/dist/chinese.postagger</code>, in which there are two files: <code>train</code> and <code>tagger</code>. The file <code>train</code> is used to train a joint model of Chinese word segmentation and POS tagging,and the file <code>tagger</code> is used to segment and assign POS tags to new texts using a trained joint model.
</p>

<h2><a id="Format-of-inputs-and-outputs">Format of inputs and outputs</a></h2>
<p>
The input files to the <code>tagger</code> are formatted as a sequence of Chinese characters. An example input is:
</p>
<pre><code> ZPar可以分析中文和英文</code></pre>

<p>
The output files contain space-separated words:
</p>
<pre><code> ZPar_NN 可以_VV 分析_VV 中文_NN 和_CC 英文_NN</code></pre>

<p>
The output format is also the format of training files for the <code>train</code> executable.
</p>

<p>
Both input and output files must be enemd in <em>utf8</em>. Here is a <a href="joint_files/gb2utf.py">script</a> that transfers files that are enemd in <em>gb</em> to the <em>utf8</em> encoding.
</p>

<h2><a id="How-to-train-a-model">How to train a model</a></h2>
<p>
To train a model, use
</p>
<pre><code> zpar/dist/chinese.postagger/train &lt;train-file&gt; &lt;model-file&gt; &lt;number of iterations&gt;</code></pre>

<p>
For example, using the <a href="joint_files/train.txt">example train file</a>, you can train a  model by
</p>
<pre><code> zpar/dist/chinese.postagger/train train.txt model 1</code></pre>

<p>
After training is completed, a new file <code>model</code> will be created in the current directory, which can be used to do joint segmentation and POS taging to Chinese. The above command performs training with one iteration (see <a href="#tuning">How to tune the performance of a system</a>) using the training file.
</p>

<h2><a id="How-to-segment-and-POS-tag-new-texts">How to segment and POS-tag new texts</a></h2>
<p>
To apply an existing model to do joint segmentation and POS tagging to new texts, use
</p>
<pre><code> zpar/dist/chinese.postagger/tagger &lt;model&gt; [&lt;input-file&gt;] [&lt;output-file&gt;]</code></pre>

<p>
where the input file and output file are optional. If the output file is not specified, segmented and POS-tagged texts will be printed to the console. If the input file is not specified, raw texts will be read from the console. For example, using the model we just trained, we can segment and POS-tag <a href="joint_files/input.txt">an example input</a> by
</p>
<pre><code> zpar/dist/chinese.postagger/tagger model input.txt output.txt</code></pre>

<p>
The output file contains automatically segmented and POS-tagged texts.
</p>

<h2><a id="Outputs-and-evaluation">Outputs and evaluation</a></h2>
<p>
Automatically segmented and POS-tagged texts contain errors. In order to evaluate the quality of the outputs, we can manually specify the segmentation and POS tags of a sample, and compare the outputs with the correct sample.
</p>

<p>
A manually specified segmentation and POS tagging of the input file is given in <a href="joint_files/reference.txt">this example reference file</a>. Here is a <a href="joint_files/evaluate.py">Python script</a> that performs automatic evaluation.
</p>

<p>
Using the above <code>output.txt</code> and <code>reference.txt</code>, we can evaluate the accuracies by typing
</p>
<pre><code> python evaluate.py output.txt reference.txt</code></pre>

<p>
You can find the precision, recall, and f-score here. See the explanation of these measures on <a href="http://en.wikipedia.org/wiki/Precision_and_recall">Wikipedia</a>.
</p>

<h2><a id="tuning">How to tune the performance of a system</a></h2>
<p>
The performance of the system after one training iteration may not be optimal. You can try training a model for another few iterations, after each you compare the performance. You can choose the model that gives the highest f-score on your test data. We conventionally call this test file the development test data, because you develop a joint segmentation and POS tagging model using this. Here is a <a href="joint_files/test.sh">a shell script</a> that automatically trains the joint segmentor and POS tagger for 30 iterations, and after the ith iteration, stores the model file to model.i. You can compare the f-score of all 30 iterations and choose model.k, which gives the best f-score, as the final model. In this file, there is a variable called <code>zpar</code>. You need to set this variable to the relative directory of <code>zpar/dist/chinese.postagger</code>.
</p>

<h2><a id="Source-code">Source code</a></h2>
<p>
The source code for the joint segmentor and POS tagger can be found at
</p>
<pre><code> zpar/src/chinese/tagger/implementation/CHINESE_TAGGER_IMPL</code></pre>

<p>
where <code>CHINESE_TAGGER_IMPL</code> is a macro defined in <code>Makefile</code>, and specifies a specific implementation for the joint segmentor and POS tagger.
</p>

<p>
The Chinese POS-tagger by default performs segmentation and tagging
simultaneously. This means that if the input sentence has been
segmented, the system will resegment the sentence. There is one
implementation that performs POS-tagging on segmented sentences. The
name of the implementation is <code>segmented</code>, and you can compile this
system by setting <code>CHINESE_TAGGER_IMPL</code> to <code>segmented</code> in <code>Makefile</code>. The
compilation, training, and usage are the same as the other taggers.
</p>

<h2><a id="reference">Reference</a></h2>
<ul>
<li>
Yue Zhang and Stephen Clark. 2008. Joint Word Segmentation and POS Tagging Using A Single Perceptron. In <em>Proc. of ACL</em>. pages 888-896.
</li>
<li>
Yue Zhang and Stephen Clark. 2010. A Fast Decoder for Joint Word Segmentation and POS-tagging Using a Single Discriminative Model. In <em>Proc. of EMNLP</em>. pages 843-852.
</li>
</ul>

</div>
</div>
<footer class="text-center">
<p>
ZPar Release 0.7
</p>
</footer>
</body>
</html>
